/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			prpex_bool.cc
  \date			june 2011
  \author		TNick

  \brief		string class


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read ReadMe.txt and Licence.txt in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<QComboBox>

#include	"prpmdl.h"
#include	"prpview.h"
#include	"prpex_bool.h"

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  FUNCTIONS    ----------------------------------------------------------- */

/* ------------------------------------------------------------------------- */
QWidget*	PEX_bool::editCreate	(QWidget *parent, const QStyleOptionViewItem &option)
{
	Q_UNUSED(option);
	QComboBox *editor = new QComboBox(parent);
	editor->addItem(QIcon(),editor->tr("True"));
	editor->addItem(QIcon(),editor->tr("False"));
	return editor;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void		PEX_bool::editLoad	(QWidget *editor)
{
	QComboBox*	qcbx = static_cast<QComboBox*>(editor);
	if (b_value)
		qcbx->setCurrentIndex(0);
	else
		qcbx->setCurrentIndex(1);
	//qcbx->showPopup();
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void		PEX_bool::editSave	(QWidget *editor)
{
	QComboBox*	qcbx = static_cast<QComboBox*>(editor);
	if (qcbx->currentIndex() == 0)
		b_value = true;
	else
		b_value = false;
	informParent();
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
bool		PEX_bool::changeVal	(QVariant new_value)
{

	if (new_value.canConvert<bool>())
		{
			if (new_value.convert(QVariant::Bool))
				{
					b_value = new_value.toBool();
					informParent();
					return true;
				}
		}

	return false;
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void		PEX_bool::editIcon	(PrpView * prp_v, QModelIndex the_idx)
{

	PrpMdl* mdl = static_cast<PrpMdl*>(prp_v->model());
	b_value = (b_value ? false : true);
	informParent();
	mdl->dataHasChanged(the_idx);

}
/* ========================================================================= */

/*  FUNCTIONS    =========================================================== */
//
//
//
//
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
